/**
 * Copyright (C) 2018-2019
 * All rights reserved, Designed By www.joolun.com
 * 注意：
 * 本软件为www.joolun.com开发研制，项目使用请保留此说明
 */
package com.ruoyi.mall.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.mall.api.RemoteOrderLogisticsService;
import com.ruoyi.mall.api.entity.OrderLogistics;
import com.ruoyi.mall.api.enums.OrderLogisticsEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

/**
 * 订单物流
 *
 * @author www.joolun.com
 * @date 2019-09-16 09:53:17
 */
@Slf4j
@RestController
@RequestMapping("/orderlogistics")
@Api(value = "orderlogistics", tags = "订单物流管理")
public class OrderLogisticsController extends BaseController {
    @DubboReference
    private RemoteOrderLogisticsService orderLogisticsService;

    /**
     * 分页查询
     *
     * @param page           分页对象
     * @param orderLogistics 订单物流
     * @return
     */
    @ApiOperation(value = "分页查询")
    @GetMapping("/page")
    @SaCheckPermission("'mall:orderlogistics:index")
    public R getOrderLogisticsPage(Page page, OrderLogistics orderLogistics) {
        return R.ok(orderLogisticsService.page(page, orderLogistics));
    }

    /**
     * 通过id查询订单物流
     *
     * @param id
     * @return R
     */
    @ApiOperation(value = "通过id查询订单物流")
    @GetMapping("/{id}")
    @SaCheckPermission("'mall:orderlogistics:get")
    public R getById(@PathVariable("id") String id) {
        return R.ok(orderLogisticsService.getById(id));
    }

    /**
     * 新增订单物流
     *
     * @param orderLogistics 订单物流
     * @return R
     */
    @ApiOperation(value = "新增订单物流")
    @PostMapping
    @SaCheckPermission("'mall:orderlogistics:add")
    public R save(@RequestBody OrderLogistics orderLogistics) {
        return R.ok(orderLogisticsService.save(orderLogistics));
    }

    /**
     * 修改订单物流
     *
     * @param orderLogistics 订单物流
     * @return R
     */
    @ApiOperation(value = "修改订单物流")
    @PutMapping
    @SaCheckPermission("'mall:orderlogistics:edit")
    public R updateById(@RequestBody OrderLogistics orderLogistics) {
        return R.ok(orderLogisticsService.updateById(orderLogistics));
    }

    /**
     * 通过id删除订单物流
     *
     * @param id
     * @return R
     */
    @ApiOperation(value = "通过id删除订单物流")
    @DeleteMapping("/{id}")
    @SaCheckPermission("'mall:orderlogistics:del")
    public R removeById(@PathVariable String id) {
        return R.ok(orderLogisticsService.removeById(id));
    }

    /**
     * 获取相关枚举数据的字典
     *
     * @param type
     * @return
     */
    @ApiOperation(value = "获取相关枚举数据的字典")
    @GetMapping("/dict/{type}")
    public R getDictByType(@PathVariable String type) {
        return R.ok(OrderLogisticsEnum.queryAll(type));
    }
}
